#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define S (siz[ls[rt]] + 1)  // 个人玄学Splay的产物，用正规Splay者跳过
#define IV inline void
#define II inline int
using namespace std;
const int O = 2e9, N = 2e4 + 10;
int t, n, ord, rt, siz[N];
int k1[N], k2[N], ls[N], rs[N];
IV lrot(int &x) {  // 左旋（让左二子成为父亲节点）
  int y = ls[x];
  ls[x] = rs[y], rs[y] = x;
  siz[y] = siz[x];
  siz[x] = siz[ls[x]] + siz[rs[x]] + 1;
  x = y;
  return;
}
IV rrot(int &x) {  // 右旋
  int y = rs[x];
  rs[x] = ls[y], ls[y] = x;
  siz[y] = siz[x];
  siz[x] = siz[ls[x]] + siz[rs[x]] + 1;
  x = y;
  return;
}
II rkx(int k, int x, int y) {  // 求最近一个x比它小的点的排名
  if (!k) return 0;
  if (x > k1[k] || (x == k1[k] && y >= k2[k]))
    return siz[ls[k]] + rkx(rs[k], x, y) + 1;
  else
    return rkx(ls[k], x, y);
}
II rky(int k, int x, int y) {  // 求最近一个y比它大的点的排名
  if (!k) return 1;
  if (y < k2[k] || (y == k2[k] && x <= k1[k]))
    return siz[ls[k]] + rky(rs[k], x, y) + 1;
  else
    return rky(ls[k], x, y);
}
IV splay(int x, int &y) {  // 个人的玄学Splay
  int o = siz[ls[y]] + 1;
  if (x == o) return;
  if (x > o)
    splay(x - o, rs[y]), rrot(y);
  else
    splay(x, ls[y]), lrot(y);
}
IV prepare() {
  memset(ls, 0, sizeof(ls));
  memset(rs, 0, sizeof(rs));
  rt = 1, k1[1] = -1, k2[1] = O;
  rs[rt] = 2, siz[1] = 2, ord = 2;
  k1[2] = O, k2[2] = -1, siz[2] = 1;
}
int main() {
  scanf("%d", &t);
  for (int x, y, k = 1; k <= t; k++) {
    scanf("%d", &n), prepare();
    printf("Case #%d:\n", k);
    while (n--) {
      scanf("%d%d", &x, &y);
      int l = rkx(rt, x, y);
      int r = rky(rt, x, y);
      if (l < r) {
        splay(l, rt),
            splay(r - S, rs[rt]);  // 个人玄学Splay的产物，用正规Splay者跳过
        int p = ls[rs[rt]] = ++ord, q = rs[rt];
        k1[p] = x, k2[p] = y, siz[p] = 1;
        siz[q] = siz[rs[q]] + 2;
        siz[rt] = siz[ls[rt]] + siz[q] + 1;
      }
      printf("%d\n", siz[rt] - 2);
    }
    if (k < t) puts("");  // 再次提醒，勿忘换行
  }
  return 0;
}
